home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / trace.n < prev    next >
Encoding:
Text File  |  1994-12-17  |  6.3 KB  |  163 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) trace.n 1.4 94/12/17 16:19:05
  9. '\" 
  10. .so man.macros
  11. .HS trace tcl
  12. .BS
  13. '\" Note:  do not modify the .SH NAME line immediately below!
  14. .SH NAME
  15. trace \- Monitor variable accesses
  16. .SH SYNOPSIS
  17. \fBtrace \fIoption\fR ?\fIarg arg ...\fR?
  18. .BE
  19.  
  20. .SH DESCRIPTION
  21. .PP
  22. This command causes Tcl commands to be executed whenever certain operations are
  23. invoked.  At present, only variable tracing is implemented. The
  24. legal \fIoption\fR's (which may be abbreviated) are:
  25. .TP
  26. \fBtrace variable \fIname ops command\fR
  27. Arrange for \fIcommand\fR to be executed whenever variable \fIname\fR
  28. is accessed in one of the ways given by \fIops\fR.  \fIName\fR may
  29. refer to a normal variable, an element of an array, or to an array
  30. as a whole (i.e. \fIname\fR may be just the name of an array, with no
  31. parenthesized index).  If \fIname\fR refers to a whole array, then
  32. \fIcommand\fR is invoked whenever any element of the array is
  33. manipulated.
  34. .RS
  35. .LP
  36. \fIOps\fR indicates which operations are of interest, and consists of
  37. one or more of the following letters:
  38. .RS
  39. .TP
  40. \fBr\fR
  41. Invoke \fIcommand\fR whenever the variable is read.
  42. .TP
  43. \fBw\fR
  44. Invoke \fIcommand\fR whenever the variable is written.
  45. .TP
  46. \fBu\fR
  47. Invoke \fIcommand\fR whenever the variable is unset.  Variables
  48. can be unset explicitly with the \fBunset\fR command, or
  49. implicitly when procedures return (all of their local variables
  50. are unset).  Variables are also unset when interpreters are
  51. deleted, but traces will not be invoked because there is no
  52. interpreter in which to execute them.
  53. .RE
  54. .LP
  55. When the trace triggers, three arguments are appended to
  56. \fIcommand\fR so that the actual command is as follows:
  57. .DS C
  58. \fIcommand name1 name2 op\fR
  59. .DE
  60. \fIName1\fR and \fIname2\fR give the name(s) for the variable
  61. being accessed:  if the variable is a scalar then \fIname1\fR
  62. gives the variable's name and \fIname2\fR is an empty string;
  63. if the variable is an array element then \fIname1\fR gives the
  64. name of the array and name2 gives the index into the array;
  65. if an entire array is being deleted and the trace was registered
  66. on the overall array, rather than a single element, then \fIname1\fR
  67. gives the array name and \fIname2\fR is an empty string.
  68. \fIOp\fR indicates what operation is being performed on the
  69. variable, and is one of \fBr\fR, \fBw\fR, or \fBu\fR as
  70. defined above.
  71. .LP
  72. \fICommand\fR executes in the same context as the code that invoked
  73. the traced operation:  if the variable was accessed as part of a
  74. Tcl procedure, then \fIcommand\fR will have access to the same
  75. local variables as code in the procedure.  This context may be
  76. different than the context in which the trace was created.
  77. If \fIcommand\fR invokes a procedure (which it normally does) then
  78. the procedure will have to use \fBupvar\fR or \fBuplevel\fR if it
  79. wishes to access the traced variable.
  80. Note also that \fIname1\fR may not necessarily be the same as the name
  81. used to set the trace on the variable;  differences can occur if
  82. the access is made through a variable defined with the \fBupvar\fR
  83. command.
  84. .LP
  85. For read and write traces, \fIcommand\fR can modify
  86. the variable to affect the result of the traced operation.
  87. If \fIcommand\fR modifies the value of a variable during a
  88. read or write trace, then the new value will be returned as the
  89. result of the traced operation.
  90. The return value from  \fIcommand\fR is ignored except that
  91. if it returns an error of any sort then the traced operation
  92. also returns an error with
  93. .VS
  94. the same error message returned by the trace command
  95. .VE
  96. (this mechanism can be used to implement read-only variables, for
  97. example).
  98. For write traces, \fIcommand\fR is invoked after the variable's
  99. value has been changed; it can write a new value into the variable
  100. to override the original value specified in the write operation.
  101. To implement read-only variables, \fIcommand\fR will have to restore
  102. the old value of the variable.
  103. .LP
  104. While \fIcommand\fR is executing during a read or write trace, traces
  105. on the variable are temporarily disabled.
  106. This means that reads and writes invoked by
  107. \fIcommand\fR will occur directly, without invoking \fIcommand\fR
  108. (or any other traces) again.
  109. .VS
  110. However, if \fIcommand\fR unsets the variable then unset traces
  111. will be invoked.
  112. .VE
  113. .LP
  114. When an unset trace is invoked, the variable has already been
  115. deleted:  it will appear to be undefined with no traces.
  116. If an unset occurs because of a procedure return, then the
  117. trace will be invoked in the variable context of the procedure
  118. being returned to:  the stack frame of the returning procedure
  119. will no longer exist.
  120. Traces are not disabled during unset traces, so if an unset trace
  121. command creates a new trace and accesses the variable, the
  122. trace will be invoked.
  123. .VS
  124. Any errors in unset traces are ignored.
  125. .VE
  126. .LP
  127. If there are multiple traces on a variable they are invoked
  128. in order of creation, most-recent first.
  129. If one trace returns an error, then no further traces are
  130. invoked for the variable.
  131. If an array element has a trace set, and there is also a trace
  132. set on the array as a whole, the trace on the overall array
  133. is invoked before the one on the element.
  134. .LP
  135. Once created, the trace remains in effect either until the
  136. trace is removed with the \fBtrace vdelete\fR command described
  137. below, until the variable is unset, or until the interpreter
  138. is deleted.
  139. Unsetting an element of array will remove any traces on that
  140. element, but will not remove traces on the overall array.
  141. .LP
  142. This command returns an empty string.
  143. .RE
  144. .TP
  145. \fBtrace vdelete \fIname ops command\fR
  146. If there is a trace set on variable \fIname\fR with the
  147. operations and command given by \fIops\fR and \fIcommand\fR,
  148. then the trace is removed, so that \fIcommand\fR will never
  149. again be invoked.
  150. Returns an empty string.
  151. .TP
  152. \fBtrace vinfo \fIname\fR
  153. Returns a list containing one element for each trace
  154. currently set on variable \fIname\fR.
  155. Each element of the list is itself a list containing two
  156. elements, which are the \fIops\fR and \fIcommand\fR associated
  157. with the trace.
  158. If \fIname\fR doesn't exist or doesn't have any traces set, then
  159. the result of the command will be an empty string.
  160.  
  161. .SH KEYWORDS
  162. read, variable, write, trace, unset
  163.